﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data.SqlClient;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeReciptInsertDataAction: BestLifeDataAction<string>
    {
            private Recipt_Detail Gvrcpt;
            private string GvRcptxml;

            public BestLifeReciptInsertDataAction(Recipt_Detail PRecipt,string Pxml)
            {
                Gvrcpt = PRecipt;
                GvRcptxml = Pxml;
            }

            public override string Body(SqlConnection PConn)
            {
                try
                {
                    SqlCommand LvCommand = new SqlCommand();
                    LvCommand.Connection = PConn;
                    LvCommand.CommandType = CommandType.StoredProcedure;
                    LvCommand.CommandText = "dbo.Insertrcptnrcptdetails";


                    //LvCommand.Parameters.Add(new SqlParameter("@R_Id", Gvrcpt.R_ID));
                    LvCommand.Parameters.Add(new SqlParameter("@D_Id", Gvrcpt.Dis_ID));
                    LvCommand.Parameters.Add(new SqlParameter("@Total_Price", Gvrcpt.Total_Price));
                    LvCommand.Parameters.Add(new SqlParameter("@Branch_Id", Gvrcpt.Branch_Id));
                    LvCommand.Parameters.Add(new SqlParameter("@Status", Gvrcpt.Status));
                    LvCommand.Parameters.Add(new SqlParameter("@Toatal_PV", Gvrcpt.Total_PV));
                    LvCommand.Parameters.Add(new SqlParameter("@Total_BV", Gvrcpt.Total_BV));
                    LvCommand.Parameters.Add(new SqlParameter("@Pay_Method", Gvrcpt.Pay_Method));
                    LvCommand.Parameters.Add(new SqlParameter("@User_Id", Gvrcpt.User_Id));
                    LvCommand.Parameters.Add(new SqlParameter("@Date_Create", Gvrcpt.Date_Create));
                    LvCommand.Parameters.Add(new SqlParameter("@Last_Modify", Gvrcpt.Last_Modify));
                    LvCommand.Parameters.Add(new SqlParameter("@Term_Id", Gvrcpt.Term_Id));
                    SqlParameter output = new SqlParameter("@Output",SqlDbType.VarChar);
                    output.Size = 10; 
                    output.Direction = ParameterDirection.Output;
                    LvCommand.Parameters.Add(output);
                    //LvCommand.Parameters.Add(new SqlParameter("@Output", Gvrcpt.Term_Id));

                    LvCommand.Parameters.Add(new SqlParameter("@rcptdetails",GvRcptxml));
                  
                    //SqlDataReader LvReader = LvCommand.ExecuteReader();
                    int LvCount = LvCommand.ExecuteNonQuery();
                    //return LvCount;
                    //string Lvreturn = LvReader.GetValue(0).ToString();
                    return output.Value.ToString();

                }
                catch (BestlifeDatabaseException e)
                {
                    throw new BestlifeDatabaseException(e);
                }

            }

        

    }
}
